package buco.integrity.osgi;

import java.util.*;

import buco.core.api.*;

public class DuplicateExportVisitor implements MetadataVisitor {

	private HashMap<String, List<Version>> exports; 
	
	public HashMap<String, List<Version>> getExports() { 
		return exports; 
	}
	
	public DuplicateExportVisitor() { 
		exports = new HashMap<String, List<Version>>(); 
	}
	
	@Override
	public void visit(RequireBundleRequirement requirement) {
	}

	@Override
	public void visit(ImportPackageRequirement requirement) {
	}

	@Override
	public void visit(ExportPackageCapability epc) {
		if(epc.getPackageVersion() == null) 
			return; 
		
		// Collect all exports and versions 
		List<Version> list = null; 
		
		if(!exports.containsKey(epc.getPackageName())) { 
			list = new ArrayList<Version>(); 
			exports.put(epc.getPackageName(), list); 
		}
		else {
			list = exports.get(epc.getPackageName()); 
		}
		
		list.add(epc.getPackageVersion());		
	}

}
